<template>
	<view>
		<view class="locale-list">
			<radio-group @change="radioChange">
				<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in locales" :key="index">
					<view>
						<radio :value="item.code" :checked="item.code === current" />
					</view>
					<view>{{item.text}}</view>
				</label>
			</radio-group>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		computed: {
			current() {
				let current = this.$i18n.locale
				return current
			},
			locales() {
				return [{
						text: this.$t('lang.chinese'),
						code: 'zh'
					}, {
						text: this.$t('lang.english'),
						code: 'en'
					},
					{
						text: this.$t('lang.italy'),
						code: 'ita'
					}
				]
			}
		},
		onShow: function() {
			uni.setNavigationBarTitle({
				title: this.$t('publicLang.languageSwitch')
			});
		},
		methods: {
			radioChange(e){
				this.$i18n.locale = e.detail.value;
				uni.setStorageSync("lang",e.detail.value)
				uni.setNavigationBarTitle({
					title: this.$t('publicLang.languageSwitch')
				});
			},
		},
		onUnload() {
			uni.setTabBarItem({
				index: 0,
				text: this.$t('navigation.home')
			})
			uni.setTabBarItem({
				index: 1,
				text: this.$t('navigation.cloudWarehouse')
			})
			uni.setTabBarItem({
				index: 2,
				text: this.$t('navigation.mine')
			})
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #FFFFFF;
	}
	.locale-list{
		margin: 20rpx;
	}
	.uni-list-cell{
		padding: 10rpx 0;
		display: flex;
	}
</style>
